package com.homegoods.videomodule;

import com.homegoods.area.model.SubModelList;
import com.homegoods.classify.model.Constant;
import com.homegoods.resource.HomeGoodsApp;
import com.homegoods.videomodule.model.CommentModel;
import com.network.retrofit_rx.Api.ActionSubscriber;
import com.network.retrofit_rx.Api.CommandImpl;
import com.network.retrofit_rx.Api.HttpManager;


import org.json.JSONObject;

import java.util.List;

import io.reactivex.functions.Consumer;

public class VideoApiUtils {
    /**
     * 获取社区视频
     * ?AppType=munityvideo_
     * token=b230e22fcf634cf8afb63e52bdf     //登录令牌
     * BindType=LoveVideo                    //统计收藏类别
     * BOWay=self$all                        //个人或全部
     */
    public static void getCommunityVideo(int pos, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.CITY_LIST)
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("AppType", "munityvideo_")
                .addParams("outdata", "jsonlist")
                .addParams("BindType", "LoveVideo")
                .addParams("BOWay", "all")
                .addParams("psize", 20)
                .addParams("pos", pos)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取视频的评论列表
     * AppType=cgmessage_byBindFile
     * MsgType=2                                //消息类型
     * SubjectSid=                              //互动主体
     * psize=50
     * pos=1
     */
    public static void getVideoCommentList(String sid, int pos, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLIST_CENTER)
                .addParams("AppType", "cgmessage_byBindFile")
                .addParams("MsgType", "3")
                .addParams("SubjectSid", sid)
                .addParams("psize", 20)
                .addParams("pos", pos)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }


    /**
     * 提交评论
     * >>>>>>>>>>>>>>>>>>>>>>>>>>>GET>>>>>>>>>>>>>>>>>>>>>>
     * token=1784378e05f94669b5acb9d31205eda2
     * <<<<<<<<<<<<<<<<<<<<<<<<<<<GET<<<<<<<<<<<<<<<<<<<<<<
     * >>>>>>>>>>>>>>>>>>>>>>>>>>>POST>>>>>>>>>>>>>>>>>>>>>
     * //【取消互动】=====================================
     * cmd=delt
     * sid=                                  //关系绑定SID
     * //【添加互动】=====================================
     * cmd=adit
     * MsgType=                                 //消息类型
     * SubjectSid=                              //互动主体
     * MsgBody=                                 //消息内容
     * ExtData={"starA":"1","starB":"2"}        //扩展字典
     * ExtAppSid=                               //扩展SID
     * //【统计互动】=====================================
     * cmd=csum
     * MsgType=                                 //消息类型
     * SubjectSid=                              //互动主体
     * //【其它说明】=====================================
     * //商品评价 MsgType=MsgCommodity
     * //视频点评 MsgType=MsgMVideo
     * //新闻评价 MsgType=MsgNews
     * //评价评价 MsgType=MsgSelf
     * <<<<<<<<<<<<<<<<<<<<<<<<<<<POST<<<<<<<<<<<<<<<<<<<<<
     */
    public static void publishComment(String sid, String msg, Consumer<JSONObject> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.CAPOOL_CGMESSAGE)
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("cmd", "adit")
                .addField("MsgType", "MsgMVideo")
                .addField("SubjectSid", sid)
                .addField("MsgBody", msg)
                .setObject(true)
                .setClass(JSONObject.class)
                .create();
        HttpManager.getInstance().postUrlForQuery(command, new ActionSubscriber<>(consumer, error, null));
    }


    /**
     * >>>>>>>>>>>>>>>>>>>>>>>>>>>GET>>>>>>>>>>>>>>>>>>>>>>
     * token=5ff890aec06d40e28070076b  //登录令牌
     * cmd=adit                        //adit,delt,selt,csum
     * <<<<<<<<<<<<<<<<<<<<<<<<<<<GET<<<<<<<<<<<<<<<<<<<<<<
     * <p>
     * >>>>>>>>>>>>>>>>>>>>>>>>>>>POST>>>>>>>>>>>>>>>>>>>>>
     * //adit 建立关系 需要token支持
     * BindType=                                //绑定类别
     * TerminatingCall=                         //被叫SID
     * AboutInf=                                //主叫说明
     * //delt 删除关系 需要token支持
     * sid=                                     //记录ID
     * //selt 查询关系 需要token支持
     * BindType=                                //绑定类别
     * TerminatingCall=                         //被叫SID
     * //csum 统计关系 无需token支持
     * BindType=                                //绑定类别
     * TerminatingCall=                         //被叫SID
     * <<<<<<<<<<<<<<<<<<<<<<<<<<<POST<<<<<<<<<<<<<<<<<<<<<
     * <p>
     * >>>>>>>>>>>>>>>>>>>>>>>>>>>OTHER>>>>>>>>>>>>>>>>>>>>
     * BindType 绑定类别 由前端统一标识即可如：
     * 新闻收藏：NewsCollectVol
     * 视频收藏：MVideoCollectVol
     * 商品收藏：CommodityCollectVol
     */
    public static void addVideoCollect(String sid, Consumer<JSONObject> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.CAPOOL_UABINDAPI)
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("cmd", "adit")
                .addField("BindType", "MVideoCollectVol")
                .addField("TerminatingCall", sid)
                .addField("AboutInf", "")
                .setObject(true)
                .setClass(JSONObject.class)
                .create();
        HttpManager.getInstance().postUrlForQuery(command, new ActionSubscriber<>(consumer, error, null));
    }

    public static void deletVideoCollect(String sid, Consumer<JSONObject> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.CAPOOL_UABINDAPI)
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("cmd", "delt")
                .addField("sid", sid)
                .setObject(true)
                .setClass(JSONObject.class)
                .create();
        HttpManager.getInstance().postUrlForQuery(command, new ActionSubscriber<>(consumer, error, null));
    }


}
